﻿@using tour.szhome.common;
@{
    ViewBag.Title = ViewBag.ID != 0 ? "编辑广告图" : "添加广告图";
}
<h3>@(ViewBag.ID != 0 ? "编辑广告图" : "添加广告图")</h3>
<div style="padding-left:50px;">
    <hr />
        <table class="tb" style="padding:5px;width:99%;">
            <tbody>
                <tr>
                    <td align="center"><span>广告图标题：</span></td>
                    <td><input type="text" id="txtAdvName" style="width:300px;" value ="@Model.AdvName" @(Model.AdvName != null ? "disabled" : "")></td>
                </tr>
                <tr>
                    <td align="center"><span>链接地址：</span></td>
                    <td><input type="text" id="txtLink" style="width:300px;" value ="@Model.Link"></td>
                </tr>
                <tr>
                    <td align="center"><span>上传图片：</span></td>
                <td>
                    <img id="Img" src=@(ViewBag.ID > 0 ? ViewBag.uploadAddress + ViewBag.Folder + Model.Img : CommPath.FileImport("manage/images/zanwutupian.gif")) style="height:320px;width:960px;border-width:0px;">       
                    <br>
                    （请上传覆盖原有图片.建议大小 960 * 320 像素）<br><br>
                    <input type="file" name="upload" id="upload" />
                    <input id="ImgV" type="hidden" value="@Model.Img" />
                </td>
                </tr>
            </tbody>
        </table>
    <hr />
    <table style="text-align :center;width:500px;">
        <tbody>
            <tr>
                <td>
                    <input type="button" value="@(ViewBag.ID != 0 ? "编辑" : "添加")" id="btnAdd" style="width:60px;">
                    <input type="button" value="返回" id="btnReturn" onclick="javascript: window.history.go(-1);" style="width:60px;">
                </td>
            </tr>
        </tbody>
    </table>
    <hr />
</div>
@CommPath.StyleImport("public/plug-in/uploadify/uploadify.css")
@CommPath.ScriptImport("public/plug-in/uploadify/jquery.uploadify-3.2.js")
<script type="text/javascript">

    $(function(){
        //上传图片欲操作
        $('#upload').uploadify({
            'buttonText': '选择文件',
            'buttonClass': 'browser',
            'width': 90,
            'height': 25,
            'formData' : {'f':"@ViewBag.Folder"},
            'fileTypeExts': '*.jpg;*.png;*.bmp;*.gif;',
            'swf': '@CommPath.FileImport("public/plug-in/uploadify/uploadify.swf")',
            'uploader': '/manage/help/UploadFiles',
            'onUploadSuccess': function (file, data, response) {
                $("#Img").attr("src", "@ViewBag.uploadAddress" + "@ViewBag.Folder" + data);
                $("#ImgV").val(data);   //要入库的路径
            },
            'onSelectError': function (file, errorCode, errorMsg) {
                switch (errorCode) {

                    case -110:
                        alert("文件 [" + file.name + "] 大小超出系统限制的" + (1024 * 1024 * 5) + "大小！");
                        break;
                    case -120:
                        alert("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        alert("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            }
        });
    });

    $("#btnAdd").bind("click", function () {
        edit();
    });

    function edit() {
        var txtAdvName = $("#txtAdvName").val();
        var txtLink = $("#txtLink").val();
        var txtImg = $("#ImgV").val();

        if (txtAdvName == "") {
            dlg.Msg.Inf("标题不能为空");
            return;
        }
        if (txtLink == "") {
            dlg.Msg.Inf("链接地址不能为空");
            return;
        }
        $.ajax({
            type: "post",
            url: "/manage/slide/json_edit",
            data: {
                AdvID: @ViewBag.ID,
                AdvName: txtAdvName,
                Link: txtLink,
                Img: txtImg
            },
            dataType: "json",
            timeout: 30000, //over time：30s
            beforeSend: function () {
                window.top.qibu.msgbox.loading("正在提交申请，请稍后... ...");
            },
            success: function (data) {
                window.top.qibu.msgbox.hide();
                if (data) {
                    dlg.Msg.Inf("操作成功");
                    setTimeout("window.history.go(-1)", 1000);
                }
                else {
                    dlg.Msg.Err("操作失败");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                window.top.qibu.msgbox.hide();
                dlg.Msg.Err(errorThrown);
            }
        });
    }
</script>